# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gplugin
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.21
pkgrel=3
arch=('any')
pkgdesc="A GObject based library that implements a reusable plugin system (mingw-w64)"
license=("LGPL 2")
url="https://bitbucket.org/rw_grim/gplugin"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libxslt")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "gettext")
options=('strip' '!debug' 'staticlibs')
source=("${_realname}-${pkgver}.tar.bz2"::https://bitbucket.org/rw_grim/${_realname}/get/v${pkgver}.tar.bz2
        001-win.patch)
sha256sums=('df6c0cb47605c5f38fed6aad216fbaa97bb47378de70103884eaa43252af0314'
            '3b5ef908992fe9073a0c14de9b58e81a0a11969f50e28fbd1a34fd7f3bbd13ce')

prepare() {
  cd rw_grim-gplugin-*

  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_SKIP_RPATH=ON \
    -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
    -DCMAKE_C_FLAGS="${CFLAGS}" \
    -DBUILD_GJS=OFF \
    -DBUILD_LUA=OFF \
    -DBUILD_PYTHON=ON \
    -DBUILD_SEED=OFF \
    -DTESTING_ENABLED=OFF \
    -DBUILD_GIR=ON \
   ../rw_grim-gplugin-*

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp ${srcdir}/rw_grim-gplugin-*/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING

  mv "${pkgdir}${MINGW_PREFIX}"/lib/libgplugin.dll "${pkgdir}${MINGW_PREFIX}"/bin/
  mv "${pkgdir}${MINGW_PREFIX}"/lib/libgplugin-gtk.dll "${pkgdir}${MINGW_PREFIX}"/bin/
}
